<?php

class MailMessage extends Base {

  /** @var string The recipient(s) of the email. */
  protected $recipient = "";

  /** @var string The recipient(s) in copy. */
  protected $cc = "";

  /** @var string The recipient(s) in hidden copy. */
  protected $bcc = "";

  /** @var string The address for reply. */
  protected $reply = "";

  /** @var string The sender address. */
  protected $sender = "";

  /** @var string The sender name to display. */
  protected $sender_name = "";

  /** @var string The subject of the email. */
  protected $subject = "";

  /** @var string The body of the email. */
  protected $body = "";

  /** @var boolean Define if the content is in HTML format. */
  protected $html = false;

  /** @var array Collection of attachment files. */
  private $attachment = null;

  /**
   * Store all parameter in private.
   * @param string $recipient The recepient
   * @param string $sender The sender
   * @param string $subject The subject
   * @param string $body The body
   * @param boolean $HTML Set to True if the body is in HTML format
   */
  public function __construct($recipient = "", $sender = "", $subject = "", $body = "", $html = false) {
    if (is_string($recipient)) {
      if (is_string($sender)) {
        if (is_string($subject)) {
          if (is_string($body)) {
            if (is_bool($html)) {
              $this->recipient = $recipient;
              $this->sender = $sender;
              $this->subject = $subject;
              $this->body = $body;
              $this->html = $html;
            } else {
              throw new IllegalArgumentException("\$html parameter should be a boolean");
            }
          } else {
            throw new IllegalArgumentException("\$body parameter should be a string");
          }
        } else {
          throw new IllegalArgumentException("\$subject parameter should be a string");
        }
      } else {
        throw new IllegalArgumentException("\$sender parameter should be a string");
      }
    } else {
      throw new IllegalArgumentException("\$recipient parameter should be a string");
    }
  }

  /**
   * Returns the attachment.
   * @return MailAttachment The attachment.
   */
  public function getAttachments() {
    return $this->attachment;
  }

  /**
   * Returns the recipient.
   * @return string The recipient.
   */
  public function getRecipient() {
    return $this->recipient;
  }

  /**
   * Returns the copy recipient.
   * @return string The copy recipient.
   */
  public function getCopy() {
    return $this->cc;
  }

  /**
   * Returns the hidden copy recipient.
   * @return string The hidden copy recipient.
   */
  public function getHiddenCopy() {
    return $this->bcc;
  }

  /**
   * Returns the address for reply.
   * @return string The address for reply.
   */
  public function getReply() {
    return $this->reply;
  }

  /**
   * Returns the sender.
   * @return string The sender.
   */
  public function getSender() {
    return $this->sender;
  }

  /**
   * Returns the sender name to display.
   * @return string The sender name.
   */
  public function getSenderName() {
    return $this->sender_name;
  }

  /**
   * Returns the subject.
   * @return string The subject.
   */
  public function getSubject() {
    return $this->subject;
  }

  /**
   * Returns the body.
   * @return string The body.
   */
  public function getBody() {
    return $this->body;
  }

  /**
   * Define if the email content is in HTML format.
   * @return boolean TRUE if the content is in HTML format.
   */
  public function isHtml() {
    return $this->html;
  }

  /**
   * Set the recipient.
   * @param string $value The recipient.
   */
  public function setRecipient($value) {
    if (is_string($value))
      $this->recipient = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Sets the copy recipient.
   * @param string $value The copy recipient.
   */
  public function setCopy($value) {
    if (is_string($value))
      $this->cc = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Sets the hidden copy recipient.
   * @param string $value The hidden copy recipient.
   */
  public function setHiddenCopy($value) {
    if (is_string($value))
      $this->bcc = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Sets the address for reply.
   * @param string $value The address for reply.
   */
  public function setReply($value) {
    if (is_string($value))
      $this->reply = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Set the sender.
   * @param string $value The sender.
   */
  public function setSender($value) {
    if (is_string($value))
      $this->sender = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Sets the sender name to display.
   * @param string $value The sender name.
   */
  public function setSenderName($value) {
    if (is_string($value))
      $this->sender_name = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Set the subject.
   * @param string $value The subject.
   */
  public function setSubject($value) {
    if (is_string($value))
      $this->subject = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Set the body.
   * @param string $value The body.
   */
  public function setBody($value) {
    if (is_string($value))
      $this->body = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a string");
  }

  /**
   * Sets the email content to HTML format, or not.
   * @param boolean True for HTML format, false otherwise.
   */
  public function setToHtml($value = true) {
    if (is_bool($value))
      $this->html = $value;
    else
      throw new IllegalArgumentException("\$value parameter should be a boolean");
  }

  /**
   * Attach a file to the mail to send.
   * @param MailAttachment $MailAttachment The file to attach to the mail.
   * @link http://be2.php.net/manual/en/function.is-a.php
   * @link http://be2.php.net/manual/en/function.array-push.php
   */
  public function attach(MailAttachment $attachment) {
    $this->attachment = $attachment;
  }

}

?>
